<!-- 音标专练列表 -->

<template>
	<view>
		<view class="container">
			<view class="container-list" v-for="(item,index) in logList" :key="item.id" @click="rereading(item,index)">
				<view class="container-list-top">
					<view class="container-list-top-left" :class="item.score > 80 ? 'autoGreed' : ''">{{ item.words }}
					</view>
					<img src="@/assets/phoneticPractice/声音@3x (1).png" @click.stop="playAudio(item.video_domain)" />
				</view>
				<view class="container-list-bottom">
					<view class="container-list-bottom-left">
						<span>[{{ item.symbol }}]</span>
						<span>{{ item.pretations }}</span>
					</view>
					<view :class="item.score < 60 ? 'autoRed' : item.score <= 80 ? 'autoYellow' : 'autoGreed'">
						{{ item.score }}
					</view>
				</view>
			</view>
		</view>
		<!-- <audio ref="audioElement" :src="audioSrc" preload="auto"></audio> -->
		<view class="container-submitTask" @click="submitTask">交作业</view>
	</view>
</template>

<script setup>
	import {
		getPhoneticPracticeLogs,
		savePhoneticPracticeLogs
	} from '@/api/phoneticPractice'

	export default {
		data() {
			return {
				title: null,
				logList: [],
				audioElement: null,
				versionId: null,
				use_time: null
			}
		},
		onLoad(options) {
			if (options) {
				this.versionId = options.versionId
				this.title = options.title
				this.use_time = options.use_time
				uni.setNavigationBarTitle({
					title: this.title
				})
			}
		},
		onShow() {
			this.getPhoneticPracticeLogs()
		},
		methods: {
			getPhoneticPracticeLogs() {
				getPhoneticPracticeLogs({
					versionId: this.versionId
				}).then(res => {
					if (res.code == 1) {
						this.logList = res.data
					}
				})
			},
			playAudio(audioUrl) {
				this.audioElement = uni.createInnerAudioContext();
				this.audioElement.src = audioUrl
				this.audioElement.autoplay = true;
			},
			rereading(item, index) {
				uni.navigateTo({
					url: '/pages/phoneticPractice/rereadingH5?versionId=' + this.versionId+"&index="+index
				})
			},
			submitTask() {
				savePhoneticPracticeLogs({
					versionId: this.versionId,
					use_time: this.use_time
				}).then(res => {
					if (res.code == 1) {
						uni.setStorageSync('phoneticPracticeWord', JSON.stringify(res.data))
						uni.navigateTo({
							url: '/pages/phoneticPractice/completeTask?title=' + this.title
						})
					}
				})
			}
		}
	}
</script>

<style scoped lang="scss">
	.container {
		// margin-top: 44px;
		padding-bottom: 65px;
		width: 100%;
		background: #F6F6F6;
		display: flex;
		flex-direction: column;
		align-items: center;
		height: 100%;
		overflow: scroll;
		padding-top: 10px;

		.container-list {
			margin-top: 10px;
			background: #FFFFFF;
			width: 355px;
			height: 77px;
			display: flex;
			flex-direction: column;
			border-radius: 5px;
			color: #8E8E8E;
			font-size: 14px;

			.container-list-top {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 10px;
				font-size: 16px;
				color: #333333;

				img {
					width: 18px;
					height: 14px;
				}
			}

			.container-list-bottom {
				display: flex;
				justify-content: space-between;
				align-items: center;
				margin: 0 10px 10px 10px;

				view:nth-child(2) {
					color: #FA192C;
				}

				.container-list-bottom-left {
					span:nth-child(2) {
						margin-left: 10px;
					}
				}

			}
		}



	}

	.container-submitTask {
		width: 355px;
		height: 45px;
		line-height: 45px;
		font-size: 18px;
		color: #ffffff;
		background: linear-gradient(to left, #29F19C, #02A1F9);
		position: fixed;
		left: 10px;
		bottom: 10px;
		text-align: center;
		border-radius: 22.5px;
	}

	.autoRed {
		color: #FA192C !important;
	}

	.autoYellow {
		color: #FF9917 !important;
	}

	.autoGreed {
		color: #0CB76C !important;
	}
</style>